package com.ruoyi.web.controller.rjgc;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.UserAddress;
import com.ruoyi.littleRedBook.service.UserAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/address")
@Api(tags = "用户地址管理")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @PostMapping
    @ApiOperation("添加收货地址")
    public AjaxResult addAddress(@ApiParam("地址信息") @RequestBody UserAddress address) {
        return userAddressService.addAddress(address);
    }

    @PutMapping
    @ApiOperation("编辑收货地址")
    public AjaxResult updateAddress(@ApiParam("地址信息") @RequestBody UserAddress address) {
        return userAddressService.updateAddress(address);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除收货地址")
    public AjaxResult deleteAddress(@ApiParam("地址ID") @PathVariable Long id) {
        return userAddressService.deleteAddress(id);
    }

    @PutMapping("/default/{id}")
    @ApiOperation("设置默认地址")
    public AjaxResult setDefaultAddress(@ApiParam("地址ID") @PathVariable Long id) {
        return userAddressService.setDefaultAddress(id);
    }

    @GetMapping
    @ApiOperation("获取当前用户的所有地址")
    public AjaxResult getAllAddresses() {
        return userAddressService.getAllUserAddresses();
    }

    @GetMapping("/default")
    @ApiOperation("获取当前用户的默认地址")
    public AjaxResult getDefaultAddress() {
        return userAddressService.getDefaultAddress();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取地址详情")
    public AjaxResult getAddressById(@ApiParam("地址ID") @PathVariable Long id) {
        return userAddressService.getAddressById(id);
    }
}
